package com.yc.utilslib.reader.protocol;

/**
 * 作者：TanTun
 * 时间：2017/10/20
 * 邮箱：32965926@qq.com
 * 描述：
 */

public enum Cmd {
    SET_TIME("设置时间", (byte)0x01),
    GET_TIME("获取时间", (byte)0x02),
    SET_PARA("设置参数", (byte)0x03),
    GET_PARA("获取参数", (byte)0x04),
    FIND_CARD("寻卡命令", (byte)0x05),
    ANTI("防冲突检测命令", (byte)0x06),
    SELECT("选卡命令", (byte)0x07),
    AUTHENTICATION("密钥认证命令", (byte)0x08),
    BLOCK_READ("块读命令", (byte)0x09),
    BLOCK_WRITE("块写命令", (byte)0x0A),
    SECTOR_READ("扇区读命令", (byte)0x0B),
    SECTOR_WRITE("扇区写命令", (byte)0x0C),
    HALT("关天线命令", (byte)0x0D),
    READ_CARD("读用户卡命令", (byte)0x0E),
    CONSUME("消费", (byte)0x0F),
    SEND_CARD_ID("发送物理卡号", (byte)0x20),
    SEND_CARD_INFO("发送卡信息", (byte)0x21);

    private String name;
    private byte value;

    Cmd(String name, byte value) {
        this.name = name;
        this.value = value;
    }

    public static String getName(byte value) {
        for (Cmd c : Cmd.values()) {
            if (c.getValue() == value) {
                return c.name;
            }
        }
        return null;
    }

    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public byte getValue() {
        return value;
    }
    public void setValue(byte index) {
        this.value = index;
    }

    public static Cmd getCmd(byte value) {
        for (Cmd c : Cmd.values()) {
            if (c.getValue() == value) {
                return c;
            }
        }
        return null;
    }
}
